import 'package:enjoy_plus/pages/home/components/home_nav.dart';
import 'package:flutter/material.dart';

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          title: const Text('享+本地生活'),
          centerTitle: true,
          backgroundColor: Colors.white,
          elevation: 0),
      backgroundColor: const Color(0xffd2dde8),
      body: ListView(
        children: [
          Container(
            padding: const EdgeInsets.all(16),
            child: HomeNav(),
          ),
          // 横幅
          Container(
            padding: const EdgeInsets.all(16),
            child: ClipRRect(
              borderRadius: BorderRadius.circular(12),
              child: Image.asset('assets/images/banner@2x.jpg'),
            ),
          ),
          // 公告栏卡片
          Container(
            decoration: BoxDecoration(
              color: Color(0xfffbfbff),
              borderRadius: BorderRadius.circular(14),
              boxShadow: [
                BoxShadow(
                  color: Colors.black.withOpacity(0.04),
                  blurRadius: 8,
                  offset: const Offset(0, 2),
                ),
              ],
            ),
            child: Column(
              children: [
                Container(
                  padding:
                      const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(14),
                    boxShadow: [
                      BoxShadow(
                        color: Colors.black.withOpacity(0.04),
                        blurRadius: 8,
                        offset: const Offset(0, 2),
                      ),
                    ],
                  ),
                  child: Container(
                    padding: const EdgeInsets.only(left: 16, right: 16),
                    child: Row(
                      children: [
                        Image.asset('assets/images/notice@2x.png',
                            width: 20, height: 20),
                        const SizedBox(width: 6),
                        const Text(
                          '社区',
                          style: TextStyle(
                              fontWeight: FontWeight.bold, fontSize: 16),
                        ),
                        const Text(
                          '公告',
                          style: TextStyle(
                            color: Color(0xfff7b500),
                            fontWeight: FontWeight.bold,
                            fontSize: 16,
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
                const SizedBox(height: 10),
                // 公告列表
                _NoticeCard(
                  title: '药品喷洒通知',
                  content: '社区定于8月3日中午喷洒灭蚊药，提醒大家看管好小孩及宠物，不要到草坪中玩耍，以免造成不必要的危险。',
                  time: '2022-08-03 16:00',
                ),
                const SizedBox(height: 10),
                _NoticeCard(
                  title: '药品喷洒通知',
                  content: '社区定于8月3日中午喷洒灭蚊药，提醒大家看管好小孩及宠物，不要到草坪中玩耍，以免造成不必要的危险。',
                  time: '2022-08-03 16:00',
                ),
              ],
            ),
          )
        ],
      ),
    );
  }
}

// 功能导航Item
class _HomeFuncNavItem extends StatelessWidget {
  final String icon;
  final String label;
  const _HomeFuncNavItem({required this.icon, required this.label});

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Image.asset(icon, width: 40, height: 40),
        const SizedBox(height: 6),
        Text(label, style: const TextStyle(fontSize: 14)),
      ],
    );
  }
}

// 公告卡片
class _NoticeCard extends StatelessWidget {
  final String title;
  final String content;
  final String time;
  const _NoticeCard({
    required this.title,
    required this.content,
    required this.time,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.only(left: 16, right: 16),
      child: Card(
        margin: EdgeInsets.zero,
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
        child: Padding(
          padding: const EdgeInsets.all(14),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(title,
                  style: const TextStyle(
                      fontWeight: FontWeight.bold, fontSize: 16)),
              const SizedBox(height: 6),
              Text(content,
                  style:
                      const TextStyle(fontSize: 14, color: Color(0xff666666))),
              const SizedBox(height: 10),
              Text(time,
                  style:
                      const TextStyle(fontSize: 12, color: Color(0xffcccccc))),
            ],
          ),
        ),
      ),
    );
  }
}
